<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib" prefix="frame"%>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript" src="${ctx}/commons/js/uploadify/jquery.uploadify.min.js"></script>
<link type="text/css" href="${ctx}/commons/js/uploadify/uploadify.css" rel="stylesheet"></link>
<body>
	
		<div class="easyui-panel" data-options="border:true,title:'投标信息'" style="padding:1px;margin-bottom: 1px;height:260px;">
			<div class="easyui-panel" data-options="border:false,title:''" style="height:200px;padding: 0px;margin-bottom: 0px">
				<table id="listChoiceBidderTable" class="easyui-datagrid" 
					data-options="singleSelect:false,toolbar:'#goodstb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,singleSelect:false,height:260,
					pagination:false,multiSort:true,remoteSort:true,striped:true,onLoadSuccess:function(data){selectRow(data);},
					url:'${ctx}/business/projectmanage/bizmanager/findValidBidInfo?id=${project.id}'">
					<thead>
						<tr>
						    <th data-options="field:'id',checkbox:true"></th>
							<th data-options="field:'bidderName',width:80,title:'投标单位',sortable:true" align="center"></th>
							<th data-options="field:'bidAmount',width:50,title:'报价金额(${project.bidType==0 ?'元':'%'})',sortable:true" align="center"></th>
							<th data-options="field:'bidTime',width:100,title:'投标时间',sortable:true,formatter: function(value,row,index){return value+'.'+row.millisecond}" align="center"></th>
							<th data-options="field:'operation',width:150,title:'操作',formatter:getOptionsBtn" align="center" ></th>
					</tr>
					</thead>
				</table>
			</div>
		</div>
		<div data-options="region:'center',title:'信息填写'" style="height:100px;border:0px">  
		   <form id="myform" method="post">
		   		<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
			    <input type="hidden" id="projectId" value="${project.id}"/>
			    <input type="hidden" id="chooseType" value="${project.chooseType}"/>

 				  <table class="infoTable">
					<tbody>
						<c:if test="${project.isAfterAudit }">
						<tr>
					        <th align='center' width="15%">是否资质后审</th>
						    <td colspan="3">
						    	<input type="radio" name='isFinishAfterAudit' value="true" checked/>是  &nbsp;&nbsp;
								<input type="radio" name='isFinishAfterAudit' value="false" />否
							</td>
					    </tr>
						</c:if>
						
					    <tr >
					        <th align='center' width="15%">选择理由</th>
						    <td colspan="3">
								<textarea name="changeReason" id="changeReason"  style="height:70px; width:450px;" oninput="checkLength('changeReasonError',200,'changeReason')" onpropertychange="checkLength('changeReasonError',200,'changeReason')" onkeyup="checkLength('changeReasonError',200,'changeReason')" data-options="required:true,validType:'isBlank'">${project.cancelReason }</textarea>
							    <font color="red"><br />注：200个字符以内，还可以输入<span class="input_font" id="changeReasonError">${200-fn:length(project.cancelReason)}</span>个字符</font>
							</td>
					    </tr>
						<tr>
							<th>中标结果选择</th>
							<td colspan="1" style="text-align: center"><a id="chooseBidder" class="easyui-linkbutton" onclick="chooseBidder();">选择中标单位</a><span id="choose1"><img style='margin-left:5px'; src='${ctx}/commons/images/ok.png'></span></td>
							<td colspan="1" style="text-align: center"><a id="lowBidder" class="easyui-linkbutton" onclick="lowBidder();">最低价中标</a><span span id="choose2"><img style='margin-left:5px'; src='${ctx}/commons/images/ok.png'></span></td>
							<td colspan="1" style="text-align: center"><a id="failureOfBid" class="easyui-linkbutton"  onclick="failureOfBid();">&nbsp;流&nbsp;&nbsp;标&nbsp;</a><span span id="choose3"><img style='margin-left:5px'; src='${ctx}/commons/images/ok.png'></span></td>
						</tr>
						<tr>
							<th>评审纪要模板</th>
							<td style="text-align: center"><a  class="easyui-linkbutton" onclick="review();" target="_blank">评审纪要</a></td>
						</tr>
						<tr>
							<th  align='center' width="15%">评审纪要</th>
							<td style="border-right: none" width="35%">
				               <div id="fileQueue" style="margin: 10px 0px 0px 10px">
							           <input type="file" name="uploadify" id="uploadify" data-options="required:true"/>
							           <p style="color: #aaaaaa;width: auto">
	                                                                                      可上传jpg,png,gif,bmp,pdf,zip,rar类型文件<br/>
				                       </p>
				                </div>
			                 </td>
							<td style="border-left: none" colspan="2">
							<c:forEach items="${resList}" var="res">
									<c:if test="${res.functionFlog==27}">
										<div><a class="easyui-linkbutton" href="javascript:showOpenFile('${ctx }','${res.id}',requestUrl);">${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
									</c:if>
								</c:forEach>
							</td>
						</tr>
						<tr>
							<th  align='center' width="15%">其他资料上传</th>
							<td style="border-right: none" width="35%">
								<div id="fileQueue1" style="margin: 10px 0px 0px 10px">
									<input type="file" name="uploadify" id="uploadify1" data-options="required:true"/>
									<p style="color: #aaaaaa;width: auto">
										可上传jpg,png,gif,bmp,pdf,zip,rar类型文件<br/>
									</p>
								</div>
							</td>
							<td style="border-left: none" colspan="2">
								<c:forEach items="${resList}" var="res">
									<c:if test="${res.functionFlog==28}">
										<div><a class="easyui-linkbutton" href="javascript:showOpenFile('${ctx }','${res.id}',requestUrl);">${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
									</c:if>
								</c:forEach>
							</td>
						</tr>
					  </tbody>
				    </table>
			   </form>
	     </div> 
</body>
	<script type="text/javascript">
		//初始化表格对应的js对象
		var projectsParamObj;
		$(function() {
			//初始化表格对象数据
			projectsParamObj = new initParams(
					{
						paramObjName : 'projectsParamObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
						tableId:'listChoiceBidderTable',
						addDataFormId:'addProjectsDataForm',
						showDialogId:'firstLevelDialog',
						searchID:'searchProjects',
						resetSearchID:'resetsearchProjects',
						searchFormID:'searchProjectsForm',
						updateUrl:"${ctx}/business/projectmanage/input?projectId=",
						deleteUrl:'${ctx}/business/projectmanage/remove',
						addDialogWidth:800,
						addDialogHeight:600,
						ctx:'${ctx}',
						addDialogTitle:'采购项目信息'
					});
			//初始化查询
			init(projectsParamObj);
			var resIds = "";
			<c:forEach items="${resList}" var="res">
            <c:if test="${res.functionFlog==11 && res.functionFlog==28}">
            resIds += ",${res.id}";
            </c:if>
			</c:forEach>
			$('#budgetMenuData').val(resIds);

			$("#uploadify").uploadify({
				'height'        : 27,   
	            'width'         : 80,    
	            'buttonText'    : '选择附件',
	            'queueID': 'fileQueue',//队列的ID
	            'queueSizeLimit':5,// 附件附列长度
				'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
				'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}?functionFlog=27',// 上传时请求的后台处理的controller
				'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
				'method':'post',  
				'folder': '',
				'preventCaching' : true,
				'fileTypeExts' :'*.jpg;*.png;*.gif;*.bmp;*.pdf;*.zip;*.rar;',
				'auto': true,
				'multi': false,//是否可多选
				'removeCompleted' : false,
				'successTimeout' : 55555,
				'onUploadSuccess':function(file, data, response){
					$('#' + file.id).find('.data').html(' 上传完毕');
                    var  budgetMenuData = $('#budgetMenuData').val();
                    $('#budgetMenuData').val(budgetMenuData+"," + data);
					//$('#budgetMenuData').val("," + data);
					var cancel=$('#fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
					$('#fileQueue .uploadify-queue-item[id!="' + file.id + '"]').html("");
					if (cancel) {
					   cancel.attr("rel", data);
					   cancel.click(function () {
						   var cancelData = cancel.attr("rel");
			               var  budgetMenuData = $('#budgetMenuData').val();
			               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
			               if(index != -1){
			            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
			            	   $('#budgetMenuData').val(budgetMenuData);
			               }
					   });
					}
				},
				'onSelectError':function(file, errorCode, errorMsg){
					switch(errorCode) {
						case -110:
							//this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
							this.queueData.errorMsg='所选文件大小超出系统限制!';
							break;
						case -120:
							//this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
							this.queueData.errorMsg='所选文件大小异常!';
							break;
						case -130:
							//this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
							this.queueData.errorMsg='所选文件类型不正确!';
							break;
					}
				},
				'onCancel' : function(file){
					alert(file);
				},
				onClose : function(){// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
					top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
					top.$("#dealDeclareUpload").uploadify('destroy');//销毁文件上传对象....
					top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
					if(top.$('#'+paramObj.showDialogId).find("object").length > 0){
						var fileQueue = top.window.document.getElementById("fileQueue");
						fileQueue.innerHTML = "";
						fileQueue.parentNode.removeChild(fileQueue);
					}
					afterClosed();
				}
			});

        $("#uploadify1").uploadify({
            'height'        : 27,
            'width'         : 80,
            'buttonText'    : '选择附件',
            'queueID': 'fileQueue1',//队列的ID
            'queueSizeLimit':5,// 附件附列长度
            'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
            'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}?functionFlog=28',// 上传时请求的后台处理的controller
            'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
            'method':'post',
            'folder': '',
            'preventCaching' : true,
            'fileTypeExts' :'*.jpg;*.png;*.gif;*.bmp;*.pdf;*.zip;*.rar;',
            'auto': true,
            'multi': false,//是否可多选
            'removeCompleted' : false,
            'successTimeout' : 55555,
            'onUploadSuccess':function(file, data, response){
                $('#' + file.id).find('.data').html(' 上传完毕');
                var  budgetMenuData = $('#budgetMenuData').val();
                $('#budgetMenuData').val(budgetMenuData+"," + data);
               // $('#budgetMenuData').val("," + data);
                var cancel=$('#fileQueue1 .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
                $('#fileQueue1 .uploadify-queue-item[id!="' + file.id + '"]').html("");
                if (cancel) {
                    cancel.attr("rel", data);
                    cancel.click(function () {
                        var cancelData = cancel.attr("rel");
                        var  budgetMenuData = $('#budgetMenuData').val();
                        var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
                        if(index != -1){
                            budgetMenuData = budgetMenuData.replace(","+cancelData,"");
                            $('#budgetMenuData').val(budgetMenuData);
                        }
                    });
                }
            },
            'onSelectError':function(file, errorCode, errorMsg){
                switch(errorCode) {
                    case -110:
                        //this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
                        this.queueData.errorMsg='所选文件大小超出系统限制!';
                        break;
                    case -120:
                        //this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
                        this.queueData.errorMsg='所选文件大小异常!';
                        break;
                    case -130:
                        //this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
                        this.queueData.errorMsg='所选文件类型不正确!';
                        break;
                }
            },
            'onCancel' : function(file){
                alert(file);
            },
            onClose : function(){// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                top.$("#uploadify1").uploadify('destroy');//销毁文件上传对象....
                top.$("#dealDeclareUpload").uploadify('destroy');//销毁文件上传对象....
                top.$("#uploadify1").uploadify('destroy');//销毁文件上传对象....
                if(top.$('#'+paramObj.showDialogId).find("object").length > 0){
                    var fileQueue = top.window.document.getElementById("fileQueue1");
                    fileQueue.innerHTML = "";
                    fileQueue.parentNode.removeChild(fileQueue);
                }
                afterClosed();
            }
        });
        });



		function deleteFile(v,resId){
			var parent = v.parentNode;
			parent.parentNode.removeChild(parent);
			var  budgetMenuData = $('#budgetMenuData').val();
	        var index = budgetMenuData.indexOf(","+resId)
	        if(index != -1){
	     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
	     	   $('#budgetMenuData').val(budgetMenuData);
	        }

            //删除数据库中的文件信息
            $.ajax({
                type : "post",
                url : "${ctx}/business/projectmanage/deleteFile?resId="+resId,
                data : top.$("#addProjectsDataForm").serialize(),
                success : function(data){

                },
                error : function(data){
                    alert("错误");
                }
            });
		}
		
		/**
		 * 操作按钮处理
		 * @param {Object} value
		 * @param {Object} row
		 * @param {Object} index
		 */
		function getOptionsBtn(value, row, index){
			var btnsHtml = "<span class='optionBtnsArea'>";
			var infoViewHtml = '<a href="javascript:void(0)" onclick="getProjectDetail(\'' + row.id + '\')" class="">详情</a>&nbsp;';
			btnsHtml+=infoViewHtml; 
			return btnsHtml +"</span>";
		}

		
		
		/**
		*投标详情
		*/
		function getProjectDetail(id){
			top.$('#secondtLevelDialog').dialog({    
			    title:"投标详情",  
			    iconCls:'icon-view',
			    width: 1000,    
			    height: 580,    
			    closed: false,    
			    inline : true,
			    cache: false,    
			    href: "${ctx}/business/projectmanage/getBidDetail?id=" + id,
			    modal: true,
				extractor : function(data){
					if($.trim(data) == "unLogin"){
						var msn = ''||i18n[''];
						msn = msn||i18n[data];
						if(msn != undefined){
							top.$.messager.alert('提示',msn,'info',function(){top.location='ctx/manage';});
							return '';
						}
					}
					return data;
				},
			    buttons : [{
						text:projectsParamObj.cancelButton,
						iconCls:'icon-cancel',
						handler:function(){
							top.$('#secondtLevelDialog').dialog('close');
						}}]
			});
			top.$('#'+projectsParamObj.showDialogId).dialog("center");
		}
	
		/** 列表loadsuccess后默认选中中标人信息**/
		function selectRow(data){
			var rowData = data.rows;
			$.each(rowData, function(index, row) {//遍历JSON
				if (row.isMultHit == true) { //如果数据行为已选中则选中改行   
					$("#listChoiceBidderTable").datagrid("selectRow", index);
				}
			});
		}

        //选择中标单位
        function chooseBidder(){
            //获取数据
            var rows = top.$('#listChoiceBidderTable').datagrid('getSelections');
            if(rows.length < 1){
                top.$.messager.alert('提示',"至少选择一条记录！",'error');
                return;
            }
            //拼装ids
            var ids=[];
            for (var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            //输入理由
            if(top.$("#changeReason").val()==""){
                top.$.messager.alert('提示',"请输入理由！",'error');
                return
            }
            loadinginfo();//显示加载框
            $.ajax({
                type : "post",
                url : "${ctx}/business/projectNb/buyer/doSubmitChoiceBidder?r="+new Date().getTime(),
                data : {
                    bidInfoIds:ids,
                    choiceType:1,//采购人选择
                    projectId:$("#projectId").val(),
                    changeReason:top.$("#changeReason").val(),
                },
                success : function(data){
                    debugger
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    if(data=="success"){
                        top.$.messager.alert("提示",'中标结果提交成功，请上传附件','info',function(){
                            $('#listChoiceBidderTable').datagrid('reload');
                            choose1();
						});
                    }else{
                        top.$.messager.alert("提示",'提交失败!',"error");
                    }
                },
                error : function(data){
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    top.$.messager.alert("提示",'提交失败!',"error");
                }
            });
        }


        //最低价中标
		function lowBidder(){
            //输入理由
            if(top.$("#changeReason").val()==""){
                top.$.messager.alert('提示',"请输入理由！",'error');
                return
            }
            loadinginfo();//显示加载框
            $.ajax({
                type : "post",
                url : "${ctx}/business/projectNb/buyer/doSubmitChoiceBidder?r="+new Date().getTime(),
                data : {
                    bidInfoIds:[""],
                    choiceType:3,//最低价选择
                    projectId:$("#projectId").val(),
                    changeReason:top.$("#changeReason").val(),
                },
                success : function(data){
                    debugger
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    if(data=="success"){
                        top.$.messager.alert("提示",'中标结果提交成功，请上传附件','info',function(){
                            $('#listChoiceBidderTable').datagrid('reload');
                            choose2();
						});
                    }else{
                        top.$.messager.alert("提示",'提交失败!',"error");
                    }
                },
                error : function(data){
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    top.$.messager.alert("提示",'提交失败!',"error");
                }
            });
		}

		//流标
		function failureOfBid(){
            //输入理由
            if(top.$("#changeReason").val()==""){
                top.$.messager.alert('提示',"请输入理由！",'error');
                return
            }
            loadinginfo();//显示加载框
            $.ajax({
                type : "post",
                url : "${ctx}/business/projectNb/buyer/doSubmitChoiceBidder?r="+new Date().getTime(),
                data : {
                    bidInfoIds:[""],
                    choiceType:2,//流标
                    projectId:$("#projectId").val(),
                    changeReason:top.$("#changeReason").val(),
                },
                success : function(data){
                    debugger
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    if(data=="success"){
                        top.$.messager.alert("提示",'流标成功，请上传附件','info',function(){
                            $('#listChoiceBidderTable').datagrid('reload');
                            choose3();
						});
                    }else{
                        top.$.messager.alert("提示",'提交失败!',"error");
                    }
                },
                error : function(data){
                    top.$('#secondtLevelDialog').dialog('close');//隐藏加载框
                    top.$.messager.alert("提示",'提交失败!',"error");
                }
            });
		}

		/*评审纪要*/
        function review(){
            var id=$("#projectId").val();
            window.open("${ctx}/business/projectNb/print/reviewRecord?projectId="+id);
        }

        function choose1(){
            $("#choose1").show();
            $("#choose2").hide();
            $("#choose3").hide();

		}
        function choose2(){
            $("#choose1").hide();
            $("#choose2").show();
            $("#choose3").hide();
        }
        function choose3(){
            $("#choose1").hide();
            $("#choose2").hide();
            $("#choose3").show();
        }


        function chooseInitialize (){
            $("#choose1").hide();
            $("#choose2").hide();
            $("#choose3").hide();
            var type=$("#chooseType").val();
            if(type==3){
                $("#choose2").show();
			}else if(type==1){
                $("#choose1").show();
			}else if(type==2){
                $("#choose3").show();
			}else{

			}
		}

		$(function(){
            chooseInitialize ();
		});


	</script>